package com.symc.his.api.impl.employee;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.symc.his.api.base.BaseApiService;
import com.symc.his.api.base.BaseResponse;
import com.symc.his.api.employee.DepartmentService;
import com.symc.his.api.employee.dto.resp.DepartmentRespDTO;
import com.symc.his.api.impl.entity.DepartmentDO;
import com.symc.his.api.impl.mapper.DepartmentMapper;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @CreateTime: 2023/4/7 22:33
 * @Version:
 * @Since: 1.8
 * @Author: 辛凤文 forward.seen@foxmail.com
 */
@RestController
public class DepartmentServiceImpl extends BaseApiService implements DepartmentService {

    @Resource
    private DepartmentMapper departmentMapper;

    @Override public BaseResponse<DepartmentRespDTO> getClinicDepartmentList() {
        LambdaQueryWrapper<DepartmentDO> queryWrapper = new LambdaQueryWrapper<DepartmentDO>()
            .eq(DepartmentDO::getDeptProperty, "01");
        BaseResponse<DepartmentRespDTO> resp = getDepartmentListByWrapper(queryWrapper);
        return resp;
    }

    @Override public BaseResponse<DepartmentRespDTO> getPharmacyDepartmentList() {
        LambdaQueryWrapper<DepartmentDO> queryWrapper = new LambdaQueryWrapper<DepartmentDO>()
            .eq(DepartmentDO::getDeptProperty, "03");
        BaseResponse<DepartmentRespDTO> resp = getDepartmentListByWrapper(queryWrapper);
        return resp;
    }

    public BaseResponse<DepartmentRespDTO> getDepartmentListByWrapper(Wrapper queryWrapper){
        List<DepartmentDO> departmentList = departmentMapper.selectList(queryWrapper);
        List<DepartmentRespDTO> departmentRespDTOList = departmentList.stream().map(dept -> {
            DepartmentRespDTO deptDTO = new DepartmentRespDTO();
            deptDTO.setDeptCode(dept.getDeptCode());
            deptDTO.setDeptName(dept.getDeptName());
            return deptDTO;
        }).collect(Collectors.toList());
        return setResultSuccess(departmentRespDTOList);
    }

}